﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace MethodWorx.Core.Validation
{
    public class StringSizeAttribute : ValidationAttribute
    {
        private int minLength;
        private int maxLength;

        public StringSizeAttribute(int minLength, int maxLength) 
            : base()
        {
            this.minLength = minLength;
            this.maxLength = maxLength;
        }

        public StringSizeAttribute(int minLength, int maxLength, string errorMessage)
            : base(errorMessage)
        {
            this.minLength = minLength;
            this.maxLength = maxLength;
        }

        public override bool IsValid(object value)
        {
            bool rv = true;

            if (value != null && !(value.ToString().Length >= this.minLength && value.ToString().Length <= this.maxLength))
                rv = false;
               

            return rv;
        }
    }
}
